Skip to main content

DB Function - Sanitize App Content

Function: sanitize_content()

Code:

    CREATE OR REPLACE FUNCTION sanitize_content()
RETURNS TRIGGER AS $$
BEGIN
NEW.content = REGEXP_REPLACE(NEW.content, '(?:\\+)u0000', '','g');
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

Environment:

  • ✅ Production
  • ✅ Staging
  • ❌ Development

Description: The sanitize_content() function is responsible for sanitizing the content field by removing any null characters (represented as '\u0000') from the input string.

Parameters:

  • None

Returns:

  • The modified NEW record.

Purpose:

  • Ensures that the content field does not contain null characters.

Usage:

  • This function is called by the trigger_sanitize_app_content trigger before inserting or updating records in the apps table.

Removal: If this function needs to be removed for any reason, execute the following in the necessary environment. This will also remove the corresponding trigger:

DROP FUNCTION sanitize_content CASCADE;

Related Documentation: